{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "03324ad6",
   "metadata": {},
   "source": [
    "* 本学习记录人：林文轩\n",
    "* 学习实践：2021-11-11\n",
    "* week06"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2ec901b",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "\n",
    "## 1.认识列表\n",
    "## 2.列表的取值\n",
    "## 3.列表的一般方法\n",
    "## 4.列表的高级方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7dadb893",
   "metadata": {},
   "source": [
    "### 1.1初始列表\n",
    "> 1. 列表的样式: [元素1,元素2,元素3……]\n",
    "> 2. 列表的性质\n",
    ">> 1. 列表是有顺序的(Sequence Types 序列类型的数据），第一个元素的位置/索引(index)是0\n",
    ">> 2. 列表可以存放不同类型的数据，**但是** 一般存放相同发类型数据\n",
    ">> 3. 列表可以按照序列数据 进行 取值 （index） & 切片(slices)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "38314b34",
   "metadata": {},
   "outputs": [],
   "source": [
    "username_datebase = \"Alex;Jack;zhichao;Marry\"\n",
    "username_datebase_list = [\"Alex\",\"Jack\",\"zhichao\",\"Marry\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cf4d24b7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jack'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 目标取出每一个账号名称\n",
    "\n",
    "username_datebase[5:9] #字符串就显得比较麻烦"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7c306e35",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Jack'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username_datebase_list[1] #列表可以按照独立元素进行取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "b5077be1",
   "metadata": {},
   "outputs": [],
   "source": [
    "#列表中可以包含不同的 types （int\\float\\str..也可是列表）数据 * 不常这样用\n",
    "different_types_list = [\"Alex\",18,175.5,[\"广东省广州市广州南方学院\",510970]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "fbff2331",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "id": "d94d4d00",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "c1780a83",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "175.5"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "08914fef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广东省广州市广州南方学院', 510970]"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "ed86735c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "510970"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "different_types_list[3][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "f131399c",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected EOF while parsing (<ipython-input-29-118bf6940f93>, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-29-118bf6940f93>\"\u001b[1;36m, line \u001b[1;32m5\u001b[0m\n\u001b[1;33m    print(squares[10]\u001b[0m\n\u001b[1;37m                     ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
     ]
    }
   ],
   "source": [
    "# 思考： 取值是否需要知道列表的长度？如果列表只有5个元素\n",
    "# 取值不能取5以上\n",
    "squares = [1,4,9,16,25]\n",
    "print(squares[0]) # 1\n",
    "# print(squares[10] SyntaxError: unexpected EOF while parsing\n",
    "# 一般 列表的取值需要先知道/清楚列表的长度，取值不要超过其长度范围\n",
    "len(squares) # 取值 不应大于长度5 位置4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "b5fecaa7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "e999380d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从左往右取 9和16：\n",
    "squares[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "033ab2b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从右往左取\n",
    "squares[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "a5d4d9dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16, 25]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从左往右取[9, 16, 25]\n",
    "squares[2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "fc2434c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[9, 16, 25]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从右往左取[9, 16, 25]\n",
    "squares[-3:]\n",
    "# 结论：取到末尾或者首位都一律不写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "ccd14568",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9]"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "08ba1e55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 9]"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取1,9？,回顾切片的步长step  [start,stop,step]\n",
    "squares[:3:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "764d90a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u'] #vowels元音\n",
    "word = \"Milliways\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "e224855e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# 检查word中出现了那些vowels中的元素，并打印出来\n",
    "# 知识点\n",
    "# 1. for 循环和if条件判断\n",
    "# 2. in 判断是否存在在列表中\n",
    "for i in word:\n",
    "    if i in vowels:\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "e918eed7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你需要查询的文本dasqweyrtoyuil;kghfmnbczx\n",
      "1 a\n",
      "5 e\n",
      "9 o\n",
      "11 u\n",
      "12 i\n"
     ]
    }
   ],
   "source": [
    "user_word = input(\"请输入你需要查询的文本\")\n",
    "for i,v in enumerate(user_word):\n",
    "    if v in vowels:\n",
    "        print(i,v)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7ee79cb",
   "metadata": {},
   "source": [
    "# 3.列表的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "56a113ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75f50349",
   "metadata": {},
   "source": [
    "> 1. append"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5ef716a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bf4e80ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack', 'Alex']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17e6d76b",
   "metadata": {},
   "source": [
    "> 2. remove"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "264f4194",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove()的一般步骤\n",
    "if \"Mary\" in names: # 先查询，再删除\n",
    "    names.remove(\"Mary\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e05ec832",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Jan', 'Jack', 'Alex']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b15cd8b",
   "metadata": {},
   "source": [
    "> 3. pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "07008294",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop() #默认删除最后一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "id": "a8168b44",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "id": "2940f03e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Mary'"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.pop(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "838e9b37",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除实践：\n",
    "stu_id_分数 = [78,80,82,84,86,88,90]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "becd4094",
   "metadata": {},
   "outputs": [],
   "source": [
    "# remove 时 ，可能需要重复运行 才可以按照指定的要求删除所有的值， \n",
    "# 分数在 低于85分 的删除\n",
    "for j in stu_id_分数:\n",
    "    if j<85: #判断是否还有值小于85 \n",
    "        for i in stu_id_分数:\n",
    "            if i < 85:\n",
    "                stu_id_分数.remove(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b719387c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[84, 86, 88, 90]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_id_分数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "57784b6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_id_分数 = [74,76,78,80,82,84,86,88,90,92,94,96]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "2330f027",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前的列表： [74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 0 74\n",
      "当值小于85时 要删除的值： 74\n",
      "当前的列表： [76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 1 78\n",
      "当值小于85时 要删除的值： 78\n",
      "当前的列表： [76, 80, 82, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 2 82\n",
      "当值小于85时 要删除的值： 82\n",
      "当前的列表： [76, 80, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 3 86\n",
      "当前的列表： [76, 80, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 4 88\n",
      "当前的列表： [76, 80, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 5 90\n",
      "当前的列表： [76, 80, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 6 92\n",
      "当前的列表： [76, 80, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 7 94\n",
      "当前的列表： [76, 80, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 8 96\n",
      "当前的列表： [76, 80, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 0 76\n",
      "当值小于85时 要删除的值： 76\n",
      "当前的列表： [80, 84, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 1 84\n",
      "当值小于85时 要删除的值： 84\n",
      "当前的列表： [80, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 2 88\n",
      "当前的列表： [80, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 3 90\n",
      "当前的列表： [80, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 4 92\n",
      "当前的列表： [80, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 5 94\n",
      "当前的列表： [80, 86, 88, 90, 92, 94, 96]\n",
      "循环遍历结果： 6 96\n"
     ]
    }
   ],
   "source": [
    "for j in stu_id_分数:\n",
    "    if j<85:\n",
    "        for i,v in enumerate(stu_id_分数):\n",
    "            print(\"当前的列表：\",stu_id_分数)\n",
    "            print(\"循环遍历结果：\",i,v)\n",
    "            if v < 85:\n",
    "                print(\"当值小于85时 要删除的值：\",stu_id_分数.pop(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "dd19879e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[80, 86, 88, 90, 92, 94, 96]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_id_分数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59f7c74e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
